#!/usr/bin/env groovy
// @file     ScanClient
// @author   Mac Radigan
// @version  $Id$

package ycoa.scan.process

import org.apache.commons.httpclient.*
import org.apache.commons.httpclient.cookie.CookiePolicy
import org.apache.commons.httpclient.cookie.CookieSpec
import org.apache.commons.httpclient.methods.*

public class ScanClient {
  private server = null;
  private port = 80;
  private user = null;
  private password = null;
  private HttpClient client = new HttpClient();

  public ScanClient(server, port) {
    this.server = server
    this.port = port
    this.user = user
    this.password = password
    client.getHostConfiguration().setHost(server, port, "http");
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  }

  public String run() {
    try {
      def url = "/ycoa/scan.glet?cmd=start"
      def get = new GetMethod(url)
      client.executeMethod(get)
      def bufferedReader = new BufferedReader( new InputStreamReader( get.getResponseBodyAsStream() ) )
      def line = ""
      def sb = new StringBuffer()
      while( (line = bufferedReader.readLine()) != null ) {
	sb.append(line)
      }
      def response = sb.toString()
      //def response = get.getResponseBodyAsString()
      get.releaseConnection()
      return response
    } catch(e) {
      throw new Exception("Unable to run scanner.", e)
    }
  } 

}

/* *EOF* */
